import yaml
from PyCmpltrtok.common import sep

if __name__ == '__main__':

    xdict = {
        'name': 'Silenthand Olleander',
        'race': 'Human',
        'traits': [
            'ONE_HAND',
            'ONE_EYE'
        ],
        'info': {
            'zh': '中文信息',
            'Japanese': 'にほんご',
            'en': 'en_US',
            'examples': {
                'int': 315,
                'ints': [315, 11, 13, -100, 0, 2024],
                'bool1': True,
                'bool0': False,
                'bools': [True, False, True, False],
                'float': 3.14159,
                'floats': [11.11, -100.01, 2e-5, 0.00002]
            }
        }
    }

    # https://stackoverflow.com/questions/10648614/dump-in-pyyaml-as-utf-8
    xstr = yaml.dump(xdict, allow_unicode=True, indent=4)
    sep()
    print(xstr)
    sep()
    path = 'dumpping.tmp.yml'
    print(f'Saving to {path}')
    with open(path, 'w', encoding='utf8') as f: # *.yml *.yaml
        r = yaml.dump(xdict, f, allow_unicode=True, indent=4)
        print(r)
    print('Saved')
